n=int(input())
k=0
maxx=0
if 999<n<10000:
    for i in range(2, int(n**0.5)+1):
        if n%i==0:
            k+=1
    if k==0:
        maxx=max(maxx, n)
    else:
        k=0
    a=n%10 #единицы
    if a>0 and a!=0:
        for i in range(2, int(a**0.5)+1):
            if a%i==0:
                k+=1
        if k==0:
            maxx=max(maxx, a)
        else:
            k=0
    n=n//10
    b=n%10 #десятки
    if b>0 and b!=0:
        for i in range(2, int(b**0.5)+1):
            if b%i==0:
                k+=1
        if k==0:
            maxx=max(maxx, b)
        else:
            k=0
    n=n//10
    c=n%10 #сотни
    if c>0 and c!=0:
        for i in range(2, int(c**0.5)+1):
            if c%i==0:
                k+=1
        if k==0:
            maxx=max(maxx, c)
        else:
            k=0
    d=n//10 #тысячи
    if d>0 and d!=0:
        for i in range(2, int(d**0.5)+1):
            if d%i==0:
                k+=1
        if k==0:
            maxx=max(maxx, d)
        else:
            k=0
    comb1=d*10+c
    if comb1>0 and comb1!=0:
        for i in range(2, int(comb1**0.5)+1):
            if comb1%i==0:
                k+=1
        if k==0:
            maxx=max(maxx, comb1)
        else:
            k=0
    comb2=c*10+b
    if comb2>0 and comb2!=0:
        for i in range(2, int(comb2**0.5)+1):
            if comb2%i==0:
                k+=1
        if k==0:
            maxx=max(maxx, comb2)
        else:
            k=0
    comb3=b*10+a
    if comb3>0 and comb3!=0:
        for i in range(2, int(comb3**0.5)+1):
            if comb3%i==0:
                k+=1
        if k==0:
            maxx=max(maxx, comb3)
        else:
            k=0
    comb4=d*100+c*10+b
    if comb4>0 and comb4!=0:
        for i in range(2, int(comb4**0.5)+1):
            if comb4%i==0:
                k+=1
        if k==0:
            maxx=max(maxx, comb4)
        else:
            k=0
    comb5=c*100+b*10+a
    if comb5>0 and comb5!=0:
        for i in range(2, int(comb5**0.5)+1):
            if comb5%i==0:
                k+=1
        if k==0:
            maxx=max(maxx, comb5)
        else:
            k=0
    print(maxx)
else:
    print(0)
